package com.ipet.manage.controller;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ipet.manage.pojo.User;

@RestController
public class TestController {

	@RequestMapping(value="/get/{name}", method=RequestMethod.GET)
	public String getMessage(@PathVariable String name){
		return "hi I am " + name;
	}
	
	
	/**
	 * 这里的@RequestMapping是对应调用端的接口中方法上面的调用
	 * @param name
	 * @return
	 */
	@RequestMapping(value="/hello/{name}", method = RequestMethod.GET)
	public String hello(@PathVariable String name){
		return "hello "+name;
	}
	
	/**
	 * 测试传输JSON对象
	 * @return
	 */
	@RequestMapping(value="/user/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public User getUser(@PathVariable Integer id){
		User user = new User();
		user.setId(id);
		user.setName("李四");
		user.setAge(18);
		return user;
	}
	
	@RequestMapping(method=RequestMethod.POST, value="/show", produces = MediaType.APPLICATION_JSON_VALUE)
	public void updateCartNum(User user){
		System.out.println("woshizhenzhendong");
	}
	
}
